<template>
  <view>
    <u-form :model="form" ref="uForm">
      <u-form-item label="品牌" prop="brand">
        <u-input   v-model="form.brand"  placeholder="请输入品牌"   @focus="clearDefault('brand')"></u-input>
      </u-form-item>
      <u-form-item label="系列" prop="series">
        <u-input v-model="form.series"   placeholder="请输入系列" @focus="clearDefault('series')" ></u-input>
      </u-form-item>
      <u-form-item label="型号" prop="model">
        <u-input v-model="form.model" placeholder="请输入型号" @focus="clearDefault('model')" ></u-input>
      </u-form-item>
	  
 
	  
      <u-button @click="submit">提交</u-button>
    </u-form>
  </view>
</template>

<script>
import toast from '../../uview-ui/libs/function/toast';

export default {
  data() {
    return {
      form: {
        brand: '',
        series: '默认系列',
        model: '默认型号'
      },
      rules: {
        brand: [
          { required: true, message: '请输入品牌', trigger: 'blur' }
        ],
        series: [
          { required: true, message: '请输入系列', trigger: 'blur' }
        ],
        model: [
          { required: true, message: '请输入型号', trigger: 'blur' }
        ]
      }
    };
  },
  onReady() {
    this.$refs.uForm.setRules(this.rules);
  },
  methods: {
    clearDefault(field) {
		console.log(field,this.form[field],this.form[field] === '默认型号');
      if (this.form[field] === '默认品牌' || this.form[field] === '默认系列' || this.form[field] === '默认型号') {
        this.form[field] = '';
      }
    },
    submit() {
      this.$refs.uForm.validate(valid => {
        if (valid) {
          console.log('验证通过', this.form);
          // 在这里处理表单提交逻辑


          let res =  this.$api.addbrand(this.form).then(res => {	 
				console.log(res);
				toast(res.msg);
				if(res.code==1)
				{
					uni.navigateTo({
						url: '/pages/wurenji/pinpai?pid='+encodeURIComponent(JSON.stringify(res.data)),						
					});
				}
				 
			});
          
        } else {
          console.log('验证失败');
        }
      });
    }
  }
};
</script>